home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWCollec / PRList.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  5.5 KB  |  175 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                PRList.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9. // Note: These classes are private to the implementation. They are not available
  10. // to part handlers.
  11. //
  12. // Note: These are primitive classes for implementing higher-level collections
  13. // For example, to create a FrameList class, subclass FW_CPrivLink to add a field to
  14. // store the frame. The FrameList class would use a FW_CPrivLinkedList in its implementation
  15. // and would manufacture the FW_CPrivLink objects internally.
  16. // 
  17. // Note: SimpleLinkedList is a list without a "seed" for consistency checking.
  18. // It cannot be iterated over.
  19.  
  20. #ifndef PRLIST_H
  21. #define PRLIST_H
  22.  
  23. #ifndef FWSTDDEF_H
  24. #include "FWStdDef.h"
  25. #endif
  26.  
  27. //========================================================================================
  28. // class FW_CPrivLink
  29. //========================================================================================
  30.  
  31. class FW_CPrivLink 
  32. {
  33. //----------------------------------------------------------------------------------------
  34. //    Constructors/Destructor
  35. //
  36. public:
  37.     FW_CPrivLink();
  38.     FW_CPrivLink(FW_CPrivLink* next, FW_CPrivLink* previous);
  39.     FW_CPrivLink( const FW_CPrivLink& );
  40.     virtual ~FW_CPrivLink();
  41.         
  42. //----------------------------------------------------------------------------------------
  43. //    New API
  44. //
  45. public:
  46.     FW_CPrivLink*         GetNext() const
  47.                             {return fNext;}    
  48.     FW_CPrivLink*         GetPrevious() const                
  49.                             {return fPrevious;}
  50.     
  51.     // The following operations are provided for efficiency, but DO NOT USE THEM
  52.     // if there are any iterators active on a list. These operations don't bump
  53.     // the list's fSeed and the iterators will not be able to detect that they
  54.     // are out of sync!
  55.         
  56.     void                  Remove();
  57.     void                  AddBefore(FW_CPrivLink *aLink);    
  58.     void                  AddAfter(FW_CPrivLink *aLink);
  59.     
  60.   //private-by-convention:
  61.           
  62.     void                  SetNext(FW_CPrivLink* aLink)                
  63.                             {fNext = aLink;}        
  64.     void                  SetPrevious(FW_CPrivLink* aLink)            
  65.                             {fPrevious = aLink;}
  66.  
  67. //----------------------------------------------------------------------------------------
  68. //    Data Members
  69. //
  70. private:
  71.     FW_CPrivLink*        fNext;
  72.     FW_CPrivLink*        fPrevious;
  73. };
  74.  
  75. //========================================================================================
  76. // class FW_CPrivLinkedList
  77. //========================================================================================
  78.  
  79. class FW_CPrivLinkedList 
  80. {
  81. public:
  82.     friend class             FW_CPrivLinkedListIterator;
  83.         
  84. //----------------------------------------------------------------------------------------
  85. //    Constructors/Destructor
  86. //
  87. public:
  88.     FW_CPrivLinkedList();
  89.     ~FW_CPrivLinkedList();
  90.           
  91. //----------------------------------------------------------------------------------------
  92. //    LinkedList API
  93. //
  94. public:
  95.     FW_Boolean                IsEmpty() const;
  96.     unsigned long            Count() const;
  97.     FW_Boolean                Includes(const FW_CPrivLink* aLink) const;
  98.     
  99.     void                    Remove(FW_CPrivLink* aLink);
  100.     void                    RemoveAll();
  101.     void                    DeleteAllLinks();
  102.     
  103.     FW_CPrivLink*            RemoveFirst();
  104.     FW_CPrivLink*            RemoveLast();
  105.     
  106.     void                    AddBefore(FW_CPrivLink* existing, FW_CPrivLink* link);
  107.     void                    AddAfter(FW_CPrivLink* existing, FW_CPrivLink* link);
  108.     void                    AddFirst(FW_CPrivLink* link);
  109.     void                    AddLast(FW_CPrivLink* link);
  110.     void                    AddLast(FW_CPrivLinkedList &list);
  111.     void                    AddLastUnique(FW_CPrivLinkedList &list);
  112.     
  113.     FW_CPrivLink*            After(const FW_CPrivLink* link) const;
  114.     FW_CPrivLink*             Before(const FW_CPrivLink* link) const;
  115.     FW_CPrivLink*            First() const;
  116.     FW_CPrivLink*             Last() const;
  117.  
  118. protected:
  119.     FW_CPrivLink*            GetSentinel()
  120.                                 {return &fSentinel;}
  121.     const FW_CPrivLink*        GetSentinel() const
  122.                                 {return &fSentinel;}
  123.     FW_Boolean                IsSentinel( const FW_CPrivLink* link ) const
  124.                                 {return link==this->GetSentinel();}
  125.     FW_Boolean                NotSentinel( const FW_CPrivLink* link ) const
  126.                                 {return link!=this->GetSentinel();}
  127.  
  128. //----------------------------------------------------------------------------------------
  129. //    Data Members
  130. //
  131. private:                  
  132.     FW_CPrivLink            fSentinel;    // Marks the head & tail
  133.     unsigned long            fSeed;        // Used to detect out-of-sync iterators
  134.     unsigned long            fCount;        // Number of elements in the list
  135. };
  136.  
  137. //========================================================================================
  138. // FW_CPrivLinkedListIterator
  139. //========================================================================================
  140.  
  141. class FW_CPrivLinkedListIterator 
  142. {
  143. //----------------------------------------------------------------------------------------
  144. //    Constructors/Destructor
  145. //
  146. public:
  147.     FW_CPrivLinkedListIterator(FW_CPrivLinkedList* list);
  148.     ~FW_CPrivLinkedListIterator();
  149.         
  150. //----------------------------------------------------------------------------------------
  151. //    FW_CPrivLinkedListIterator API
  152. //
  153. public:
  154.     FW_CPrivLink*            First();
  155.     FW_CPrivLink*            Next();
  156.     FW_CPrivLink*            Last();
  157.     FW_CPrivLink*            Previous();
  158.     FW_CPrivLink*            Current();
  159.     FW_Boolean                 IsNotComplete();
  160.     void                    RemoveCurrent();
  161.         
  162. //----------------------------------------------------------------------------------------
  163. //    Data Members
  164. //
  165. private:
  166.     FW_CPrivLinkedList*        fList;
  167.     FW_CPrivLink*            fCurrent;
  168.     FW_CPrivLink*            fNext;        // Used only when deleting while iterating
  169.     FW_CPrivLink*             fPrevious;    // Used only when deleting while iterating
  170.     FW_CPrivLink*            fSentinel;
  171.     unsigned long            fSeed;        // Used to detect out-of-sync iterators    
  172. };
  173.  
  174. #endif // FWLIST_H
  175.